# 定义路径
$source = "C:\Users\Kulumi\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
$tempDestination = "C:\Users\Kulumi\Pictures\Camera Roll"
$landscapeDir = "D:\Picture\图像 景象\风景 锁屏横板"
$portraitDir = "D:\Picture\图像 景象\风景 锁屏竖板"

# 创建目录（如果不存在）
foreach ($dir in ($tempDestination, $landscapeDir, $portraitDir)) {
    if (-not (Test-Path -Path $dir)) {
        New-Item -Path $dir -ItemType Directory | Out-Null
    }
}

# 复制大于100KB的文件
Get-ChildItem -Path $source -File | Where-Object { $_.Length -gt 102400 } | ForEach-Object {
    Copy-Item -Path $_.FullName -Destination (Join-Path $tempDestination $_.Name) -Force
}

# 为非.bat和非.jpg文件添加.jpg后缀
Get-ChildItem -Path $tempDestination -File | Where-Object { 
    $_.Extension -ne ".bat" -and $_.Extension -ne ".jpg"
} | ForEach-Object {
    Rename-Item -Path $_.FullName -NewName "$($_.BaseName).jpg" -Force
}

# 根据图片尺寸分类移动
Add-Type -AssemblyName System.Drawing
Get-ChildItem -Path $tempDestination -Filter *.jpg -File | ForEach-Object {
    try {
        $img = [System.Drawing.Image]::FromFile($_.FullName)
        if ($img.Width -gt $img.Height) {
            # 横版图片
            Move-Item -Path $_.FullName -Destination $landscapeDir -Force
        }
        else {
            # 竖版图片
            Move-Item -Path $_.FullName -Destination $portraitDir -Force
        }
        $img.Dispose()
    }
    catch {
        Write-Warning "无法处理文件 $($_.Name): $_"
    }
}
